package com.gmako.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.gmako.entity.StatAccount;
import com.gmako.service.StatService;
import com.gmako.utils.ResponseUtils;


@Controller
@RequestMapping("/statLogin.do")
public class statController extends BaseController {
	@Autowired(required = false)
	private StatService statService;

	/**
	 * state登录
	 * 
	 * @author Warlock叶
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping
	public String statLogin(HttpServletRequest request,
			HttpServletResponse response) {
		String username = request.getParameter("name");
		String pwd = request.getParameter("pwd");
		StatAccount stat = statService.statLogin(username, pwd);
		if (stat != null) {
			request.getSession().setAttribute("STATUser", stat);
			ResponseUtils.renderText(response, "1");
		} else {
			ResponseUtils.renderText(response, "密码不正确");
		}
		return null;
	}

	/**
	 * 登出STAT
	 * 
	 * @author Warlock叶
	 * @param request
	 * @param response
	 * @return
	 */

	@RequestMapping(params = "method=loginOutManage")
	public ModelAndView loginOutStat(HttpServletRequest request,
			HttpServletResponse response) {
		request.getSession().removeAttribute("STATUser");
		ModelAndView mav = new ModelAndView("forward:/admin/Manage_login.jsp");
		return mav;
	}

	/**
	 * 测试方法
	 * 
	 * @author Warlock叶
	 * @param request
	 * @param response
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */

	@RequestMapping(params = "method=test")
	public void test(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		managerLoginIs(request, response);
	}

}
